<jsp:useBean id="db" scope="session" class="com.jipl.Masters.DatabaseBean"/> 
<jsp:setProperty name="db" property="*"/>
<%@ page import="java.io.* , java.util.*, java.sql.*"%>
<html xmlns="http://www.w3.org/1999/xhtml">
    <!-- DW6 -->
    <head>
        <!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
        <title>Edit Purchase Entry</title>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <script language="JavaScript" type="text/javascript">
            //--------------- LOCALIZEABLE GLOBALS ---------------
            var d=new Date();
            var monthname=new Array("January","February","March","April","May","June","July","August","September","October","November","December");
            //Ensure correct for language. English is "January 1, 2004"
            var TODAY = monthname[d.getMonth()] + " " + d.getDate() + ", " + d.getFullYear();
            //---------------   END LOCALIZEABLE   ---------------
        </script>

        <link href="../../images/mm_health_nutr.css" rel="stylesheet" type="text/css">
        <style type="text/css">
            <!--
            a:link {
                text-decoration: none;
            }
            a:visited {
                text-decoration: none;
            }
            a:hover {
                text-decoration: none;
            }
            a:active {
                text-decoration: none;
            }
            a {
                font-weight: bold;
            }
            .style1 {
                font-size: 14px;
                font-weight: bold;
            }
            .style5 {font-weight: bold}
            .style7 {color: #E8F3C2; font-weight: bold; }
            .style8 {color: #E8F3C2}
            -->
        </style>
    </head>
    <body bgcolor="#F4FFE4">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr bgcolor="#D5EDB3">
                <td width="251" rowspan="2" background="../../images/mm_health_photo copy.jpg">&nbsp;</td>
                <td width="535" height="50" align="center" valign="bottom" nowrap="nowrap" background="../../images/flash_header1.png" id="logo"><span class="style5">Stores and Material Management</span></td>
                <td width="192" background="../../images/flash_header1.png">&nbsp;</td>
            </tr>

            <tr bgcolor="#D5EDB3">
                <td height="51" align="center" valign="top" background="../../images/flash_header2.png" id="tagline">&nbsp;</td>
                <td width="192" background="../../images/flash_header2.png">&nbsp;</td>
            </tr>

            <tr>
                <td colspan="3" bgcolor="#5C743D"><img src="../../images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td>
            </tr>

            <tr>
                <td colspan="3" bgcolor="#99CC66" background="../../images/mm_dashed_line.gif"><img src="../../images/mm_dashed_line.gif" alt="line decor" width="4" height="3" border="0" /></td>
            </tr>

            <tr bgcolor="#99CC66">
                <td height="20" background="../../images/flash_menubar.png"><a href="../Entries.jsp">HOME::</a>&nbsp;&nbsp;<a href="PurchaseHome.jsp">BACK </a>::&nbsp;&nbsp;
                    <script language="JavaScript" type="text/javascript">
                        document.write(TODAY);	</script>	</td>
                <td height="20" align="center" background="../../images/flash_menubar.png"><a href="../../masters/Masters.jsp">Masters</a> <a href="../Entries.jsp">Entries</a> <a href="../../reports/AdminReporting.jsp">Reports</a></td>
                <td height="20" background="../../images/flash_menubar.png">&nbsp;</td>
            </tr>

            <tr>
                <td colspan="3" bgcolor="#99CC66" background="../../images/mm_dashed_line.gif"><img src="../../images/mm_dashed_line.gif" alt="line decor" width="4" height="3" border="0" /></td>
            </tr>

            <tr>
                <td colspan="3" bgcolor="#5C743D"><img src="../../images/mm_spacer.gif" alt="" width="1" height="2" border="0" /></td>
            </tr>
            <tr>
                <td height="544" colspan="3" align="center" valign="top" bgcolor="#536A3E">&nbsp;
                    <form name="form1" method="post" action="">
                        <table width="225" border="1" align="center">
                            <tr align="center">
                                <td height="29" colspan="2" background="../../images/flash_header1.png"><span class="style1">Purchase Delete </span></td>
                            </tr>
                            <tr>
                                <td width="103" background="../../images/flash_body2.png"><span class="style7">Purchase ID </span></td>
                                <td width="106" background="../../images/flash_body2.png">
                                    <span class="style7">
                                        <select name="pid">
                                            <option></option>
                                            <%
                                                db.connect();
                                                request.getSession(true);
                 String user=session.getAttribute("un").toString();
                  String user_name_query="select distinct(location) from user_reg where uid='"+user+"';";
                        String loc="";
                        ResultSet rs21=db.execSQL(user_name_query);
                        if (rs21.next()==true)
                                        loc=rs21.getString(1);
                        else if(rs21.next()==false)
                                          {
                                                  String qad1="SELECT location FROM admin where un='"+user+"' ";
                                                  ResultSet rst1=db.execSQL(qad1);
                                                  if(rst1.next()==true)
                                                  {
                                                                loc=rst1.getString(1);
                                                  }
                                          }
                                                String get_id="select distinct(pid) from purchase where location='"+loc+"'";
                                                ResultSet getid=db.execSQL(get_id);
                                                while (getid.next()==true)
                                                {
                                            %>
                                            <option><%=getid.getString(1)%></option>
                                            <%}%>
                                        </select>
                                    </span> </td>
                            </tr>
                            <tr>
                                <td colspan="2" align="center" background="../../images/flash_body2.png"><span class="style8">
                                        <label>
                                            <input type="submit" name="Submit" value="Submit">
                                        </label>
                                    </span></td>
                            </tr>
                        </table>
                    </form>


                    <%
                    if (request.getParameter("Submit")!=null)
                    {
                               String pid=request.getParameter("pid");
                                   request.getSession(true);
                                   session.setAttribute("pid",pid);
                                   String getitems="select iname,qty,value from purchase where pid='"+pid+"'";
                                   ResultSet gitems=db.execSQL(getitems);
                                   out.println("<form name='form2' method='post' action='purchaseAction.jsp'>");
                                   out.println("<table width='460' border='1'>");
                       out.println("<tr align='center'>");
                       out.println("<td height='28' colspan='3' background='../../images/flash_header1.png'>");
                                   out.println("<span class='style1'>Purchase Invoice "+pid+" Details</span></td>");
                       out.println("</tr>");
                       out.println("<tr>");
                       out.println("<td width='144' height='27' background='../../images/flash_header1.png'>");
                                   out.println("<span class='style1'>Item Name </span></td>");
                       out.println("<td width='146' background='../../images/flash_header1.png'><span class='style1'>Qty</span></td>");
                       out.println("<td width='148' background='../../images/flash_header1.png'><span class='style1'>Value</span></td>");
                        out.println("   </tr>");
                                   String item="";
                                   while (gitems.next()==true)
                                   {
                                   item=gitems.getString(1);
                                           String check="select * from estimateitems where iname='"+item+"'";
                                           System.out.println(check);
                                           ResultSet r1=db.execSQL(check);
	
                                           String check2="select * from allocation where itemname='"+item+"'";
                                           System.out.println(check2);
                                           ResultSet r2=db.execSQL(check2);
		
                                           String check3="select * from acceptance where rem='"+item+"'";
                                           System.out.println(check3);
                                           ResultSet r3=db.execSQL(check3);
		
                                           String check4="select * from workentry where itemname='"+item+"'";
                                           System.out.println(check4);
                                           ResultSet r4=db.execSQL(check4);
		
                           if (r1.next()==false && r2.next()==false && r3.next()==false && r4.next()==false)
                           {
                                   out.println("<tr>");
                       out.println("<td><label>");
                       out.println("<input name='iname' type='text' id='iname' value='"+item+"'>);");
                        out.println("     </label></td>");
                        out.println("     <td><label>");
                        out.println("     <input name='qty' type='text' id='qty' value='"+gitems.getInt(2)+"'>");
                        out.println("     </label></td>");
                        out.println("     <td><label>");
                        out.println("     <input name='value' type='text' id='value' value='"+gitems.getDouble(3)+"'>");
                        out.println("     </label></td>");
                       out.println("    </tr>  ");
                                   } else {
                                   out.println("<span class='style7'>Items already In use</span><a href= 'PurchaseHome.jsp'>Go to Purchase Home</a>");	 break;
                                   }%>
                    <%}
                             out.println(" <tr>");
                     out.println("<td colspan='3' align='center'><label>");
                     out.println("<input name='Delete' type='submit' id='Delete' value='Delete'>");
                      out.println("</label></td>");
                      out.println("</tr>");
                    out.println(" </table>");
                 out.println("  </form>	");
                    }%></td>
            </tr>

            <tr>
                <td colspan="3" background="../../images/flash_body1.png">&nbsp;</td>
            </tr>
        </table>
    </body>
</html>
